package com.team.cloudsharing.dao.file;

import java.io.Serializable;
import java.util.Date;
import java.util.Set;

import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import javax.persistence.GenerationType;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;
import javax.persistence.Temporal;
import javax.persistence.TemporalType;

import org.hibernate.annotations.Cascade;
import org.hibernate.annotations.CascadeType;

import com.team.cloudsharing.dao.backupfile.BackUpFileDO;
import com.team.cloudsharing.dao.folder.FolderDO;

@Entity
@Table(name = "file")
public class FileDO implements Serializable{

	private static final long serialVersionUID = 1L;

	@Id
	@Column(name = "file_id")
	@GeneratedValue(strategy = GenerationType.IDENTITY)
	private Long fileId;
	
	@Column(name = "file_name", nullable = false)
	private String fileName;
	
	@Column(name = "file_path", nullable = true)
	private String filePath;
	
	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "date_create", nullable = false, columnDefinition = "TIMESTAMP DEFAULT CURRENT_TIMESTAMP")
	private Date dateCreate = new Date();

	@Temporal(TemporalType.TIMESTAMP)
	@Column(name = "modified_date", nullable = false)
	private Date modifiedDate = new Date();
	
	@Column(name = "modified_user_id", nullable = false)
	private Long modifiedUserId;
	
	@Column(name = "file_capacity", nullable = false)
	private Long fileCapacity;
	
	@Column(name = "file_url", nullable = false)
	private String fileUrl;
	
	@Column(name = "is_file_in_trash", nullable = false)
	private boolean isFileInTrash = false;
	
	@Column(name = "is_file_backup", nullable = false)
	private boolean isFileBackup = false;
	
	@Column(name = "file_permission", nullable = false)
	private Integer filePermission;
	
	@Column(name = "file_password", nullable = true)
	private String filePassword;
		
	@ManyToOne(fetch = FetchType.LAZY)
	@JoinColumn(name = "folder_id", nullable = false)
	private FolderDO folderDO;
	
	@OneToMany(mappedBy = "fileDO", fetch = FetchType.EAGER)
	@Cascade({CascadeType.DELETE, CascadeType.SAVE_UPDATE})
	private Set<BackUpFileDO> backUpFileDO;

	public FileDO() {
	}
	public FileDO(String fileName, String filePath, String fileUrl, long fileCapacity, Date modifiedDate, Long modifiedUserId, int filePermission, FolderDO folderDO) {
		super();
		this.fileName = fileName;
		this.filePath = filePath;
		this.fileUrl = fileUrl;
		this.fileCapacity = fileCapacity;
		this.modifiedDate = modifiedDate;
		this.modifiedUserId = modifiedUserId;
		this.filePermission = filePermission;
		this.folderDO = folderDO;
	}

	public Long getFileId() {
		return fileId;
	}

	public void setFileId(Long fileId) {
		this.fileId = fileId;
	}

	public String getFileName() {
		return fileName;
	}

	public void setFileName(String fileName) {
		this.fileName = fileName;
	}

	public String getFilePath() {
		return filePath;
	}

	public void setFilePath(String filePath) {
		this.filePath = filePath;
	}

	public Date getDateCreate() {
		return dateCreate;
	}
	public void setDateCreate(Date dateCreate) {
		this.dateCreate = dateCreate;
	}

	public Date getModifiedDate() {
		return modifiedDate;
	}

	public void setModifiedDate(Date modifiedDate) {
		this.modifiedDate = modifiedDate;
	}

	public Long getModifiedUserId() {
		return modifiedUserId;
	}

	public void setModifiedUserId(Long modifiedUserId) {
		this.modifiedUserId = modifiedUserId;
	}

	public Long getFileCapacity() {
		return fileCapacity;
	}
	public void setFileCapacity(Long fileCapacity) {
		this.fileCapacity = fileCapacity;
	}
	public String getFileUrl() {
		return fileUrl;
	}
	public void setFileUrl(String fileUrl) {
		this.fileUrl = fileUrl;
	}
	public boolean isFileInTrash() {
		return isFileInTrash;
	}

	public void setFileInTrash(boolean isFileInTrash) {
		this.isFileInTrash = isFileInTrash;
	}

	public boolean isFileBackup() {
		return isFileBackup;
	}

	public void setFileBackup(boolean isFileBackup) {
		this.isFileBackup = isFileBackup;
	}

	public Integer getFilePermission() {
		return filePermission;
	}

	public void setFilePermission(Integer filePermission) {
		this.filePermission = filePermission;
	}

	public FolderDO getFolderDO() {
		return folderDO;
	}

	public void setFolderDO(FolderDO folderDO) {
		this.folderDO = folderDO;
	}

	public Set<BackUpFileDO> getBackUpFileDO() {
		return backUpFileDO;
	}

	public void setBackUpFileDO(Set<BackUpFileDO> backUpFileDO) {
		this.backUpFileDO = backUpFileDO;
	}

	public static long getSerialversionuid() {
		return serialVersionUID;
	}
	
}
